#pragma once
#include <string>
#include "protocol.hpp"
#include <iostream>
#include <cmath>

class calculator
{
public:
    calculator()
    {
    }
    ~calculator()
    {
    }
    Response execute(const Request &req)
    {
        Response resp;
        switch (req.Oper())
        {
        case '+':
            resp.setResult(req.X() + req.Y());
            break;
        case '-':
            resp.setResult(req.X() - req.Y());
            break;
        case '*':
            resp.setResult(req.X() * req.Y());
            break;
        case '/':
        {
            if (req.Y() == 0)
            {
                resp.setCode(1); // 1就是错误 /0 
                break;
            }
            resp.setResult(req.X() / req.Y());
        }
        break;
        case '%':
        {
            if (req.Y() == 0)
            {
                resp.setCode(2); // 2就是错误 mod 0
                break;
            }
        }
            resp.setResult(fmod(req.X(), req.Y()));
            break;
        default:
            resp.setCode(3); // request do not suport
            break;
        }

        return resp;
    }

private:
};